package com.atguigu.gulimall.product.web;

import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.vo.Catalog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author zhuguanming
 * @description 首页
 * @date 2021/5/27 21:30
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/", "/index.html"})
    public String toIndex(Model model){
        //视图解析器默认拼接  prefix： classpath:/templates/    suffix： .html
        model.addAttribute("categories", categoryService.queryTopCategoryList());
        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String,List<Catalog2Vo>> getCatalogJson(){
        return categoryService.getCatalogJson();
    }
}
